﻿using System;
using Besture.Bll;
using Besture.Common;
using Besture.Common.Helper;
using Besture.Model;
using System.Data;

namespace Besture.UI
{
    public partial class RelatedAdvisorySet : BasePage
    {
        #region 页面加载事件

        /// <summary>
        /// 页面加载
        /// </summary>
        protected override void InitialLoad()
        {
            //页面加载
            InitPage();
            //编辑编号
            InitData(ID);
        }

        /// <summary>
        /// 回发
        /// </summary>
        protected override void PostBackLoad()
        {

        }

        /// <summary>
        /// 页面加载
        /// </summary>
        public void InitPage()
        {

        }

        /// <summary>
        /// 数据加载
        /// </summary>
        /// <param name="id">编号</param>
        protected void InitData(int id)
        {
            if (id == 0) return;

            var dac = new RelatedAdvisoryDac();
            var model = dac.GetModel(id);
            if (model == null) return;
            lblContent.Text = model.Content;
            txtReply.Text = model.Reply;

            var hotModel = new HotelsDac().GetModel(model.HotelsID);
            if (hotModel != null)
                lblHotelsName.Text = hotModel.HotelsName;
            var userBaseModel = new UserBaseDac().GetModel(model.UserID);
            if (userBaseModel != null)
                lblUserName.Text = userBaseModel.LoginName;

        }
        #endregion

        #region 保存

        protected void BtnSubmitClick(object sender, EventArgs eventArgs)
        {
            var dac = new RelatedAdvisoryDac();
            RelatedAdvisoryModel model = null;
            var baseDac = new BaseDac<RelatedAdvisoryModel>();
            model = dac.GetModel(ID);
            model.Reply = txtReply.Text.Trim();
            model.ReplyAdminUserID = AdminUserService.AdminLoginUser.ID; ;
            model.ReplyTime = DateTime.Now;
            //加载修改基本数据
            baseDac.LoadUpdateBaseModel(model);
            if (dac.Update(model) > 0)
                FunHelper.Alert("保存成功", ListUrl());
        }
        #endregion
    }
}